﻿function contentPageLoad() {
    var nom = $get(txtNombre);
    var correo = $get(txtCorreo);
    var tel = $get(txtTel);
    var Doctxt = $get(cmbDoc + "_ddlControl1_TextBox")

    nom.onfocus = function () { setClassDefault(1); }
    correo.onfocus = function () { setClassDefault(2); }
    tel.onfocus = function () { setClassDefault(3); }
    Doctxt.onfocus = function () { setClassDefault(4); }
}

function setClassDefault(field) {
    var nom = $get(txtNombre);
    var correo = $get(txtCorreo);
    var tel = $get(txtTel);
    var DocExt = $get(cmbDoc.replace("_ddlControl1", ""));
    var Doctxt = $get(cmbDoc + "_ddlControl1_TextBox")

    switch(field)
    {
        case 1:
            nom.className = "textbox";
            break;
        case 2:
            correo.className = "textbox";
            break;
        case 3:
            tel.className = "textbox";
            break;
        case 4:
            Doctxt.className = "";
            DocExt.getElementsByClassName("bcmb").bcmb.className = "bcmb";
            break;
    }
}

function mostrarsecc(secc) {
    switch (secc) {
        case 1:
            var options = {};
            document.getElementById("pag1").style.display = "none";
            document.getElementById("pag2").style.display = "none";
            document.getElementById("pag3").style.display = "none";
            $("#pag1").effect("slide", options, 1200); //show(1500);
            break;
        case 2:
            var options = {};
            if (validaSecc1()) {
                document.getElementById("pag1").style.display = "none";
                document.getElementById("pag2").style.display = "none";
                document.getElementById("pag3").style.display = "none";
                $("#pag2").effect("slide", options, 1200); //show(1500);
            }
            break;
        case 3:
            var options = {};
            document.getElementById("pag1").style.display = "none";
            document.getElementById("pag2").style.display = "none";
            document.getElementById("pag3").style.display = "none";
            $("#pag3").effect("slide", options, 1200); //show(1500);
            break;
        case 4:
            var options = {};
            document.getElementById("pag1").style.display = "none";
            document.getElementById("pag2").style.display = "none";
            document.getElementById("pag3").style.display = "none";
            $("#pag4").effect("slide", options, 1200); //show(1500);
            break;
    }
    
    return false;
}

function Print() {
    window.print();
}

function validaSecc1() {
    var nom = $get(txtNombre);
    var correo = $get(txtCorreo);
    var tel = $get(txtTel);
    var Doc = $get(cmbDoc);
    var DocExt = $get(cmbDoc.replace("_ddlControl1", ""));
    var Doctxt = $get(cmbDoc + "_ddlControl1_TextBox")
    var ban = true;

    nom.className = "textbox";
    correo.className = "textbox";
    tel.className = "textbox";
    Doctxt.className = "";
    DocExt.getElementsByClassName("bcmb").bcmb.className = "bcmb";
    
    if (nom.value.trim() == "") {
        nom.className = "InvalidField";
        ban = false;
    }

    if (tel.value.trim() == "") {
        tel.className = "InvalidField";
        ban = false;
    }

    if (correo.value.trim() == "") {
        correo.className = "InvalidField";
        ban = false;
    }
    else {
        if (!Util.ValidMail(correo.value.trim())) {
            correo.className = "InvalidField";
            ShowMsg("Favor de capturar un correo electrónico valido.");
            return false;
        }
    }
    
    if (Util.GetValueCombo(cmbDoc) == null) {
        Doctxt.className = "InvalidField";
        DocExt.getElementsByClassName("bcmb").bcmb.className = "bcmb InvalidField"
        ban = false;
    }

    if (!ban) ShowMsg("Favor de capturar todos los campos marcados como requeridos.");
    return ban;
}

//function selectDay(day) {
//    $get(hdnDay).value = day;
//    $get("diasel").innerHTML = "&nbsp;&nbsp;<b>" + day + "</>";
//    return false;
//}

function EnviaCita() {
    var nom = $get(txtNombre);
    var correo = $get(txtCorreo);
    var tel = $get(txtTel);
    var Doc = $get(cmbDoc);
    var DocExt = $get(cmbDoc.replace("_ddlControl1", ""));
    var Doctxt = $get(cmbDoc + "_ddlControl1_TextBox")
    var Fecha = $get(dpFecha);
    var fecha = Fecha.value.split("/");
    Fecha = fecha[2].toString() + fecha[1].toString() + fecha[0].toString();
    var hora = $get(ddlHora);
    var com = $get(txtComentarios);

    var obj = {
        "Nombre": nom.value,
        "CorreoElectronico": correo.value,
        "Telefono": tel.value,
        "IdDoctor": Util.GetValueCombo(cmbDoc),
        "Fecha": fecha,
        "Hora": hora.value,
        "Comentarios": com.value
    };

    PageMethods.EnviaCita(obj, OnSucceeded, OnFailed);
}

function OnSucceeded(valor) {
    mostrarsecc(4);
}

function OnFailed(error) {
    ShowMsg(error.get_message());
}